---
title: useUnmounted
description: The useUnmounted hook can be used to cancel setting state for an unmount component after firing and async action.
docType: API Docs
docGroup: Hooks
group: Low-level
hooks: [useUnmounted]
---

# useUnmounted [$SOURCE](packages/core/src/useUnmounted.ts)

```ts disableTransform
function useUnmounted(): NonNullRef<boolean>;
```

## Example Usage

```tsx
import { useUnmounted } from "@react-md/core";
import { useEffect, useState } from "react";

function Example(): ReactElement {
  const [state, setState] = useState({ loading: false });
  const unmounted = useUnmounted();

  useEffect(() => {
    async function load(): void {
      const result = await fetch("/some-api");
      const json = await response.json();
      if (!unmounted.current) {
        setState({ loading: false, result: json });
      }
    }

    setState({ loading: true });
    load();
  }, [unmounted]);

  return null;
}
```

## Parameters

None.

## Returns

A `NonNullRef<boolean>` that can be used to check if currently unmounted.
